package cn.outsourcing.supermarket.converter;

import cn.outsourcing.supermarket.converter.transform.BooleanToIntegerTransform;
import cn.outsourcing.supermarket.dto.backstage.BackstageAdInfoDTO;
import cn.outsourcing.supermarket.po.HiolabsAd;
import cn.outsourcing.supermarket.vo.backstage.BackstageAdInfoVO;
import cn.outsourcing.supermarket.vo.hiolabs.HiolabsAdVO;
import cn.outsourcing.supermarket.vo.home.HomeBannerVO;
import org.mapstruct.IterableMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Named;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * @author gzkemays
 * @since 2021/10/22 1:19
 */
@Mapper(uses = {BooleanToIntegerTransform.class})
public interface HiolabsAdConverter {
  HiolabsAdConverter INSTANCE = Mappers.getMapper(HiolabsAdConverter.class);

  /**
   * 返回小程序广告列表
   *
   * @param ad 原 po 列表
   * @return 程序广告列表
   */
  List<HomeBannerVO> converterToBanner(List<HiolabsAd> ad);
  /**
   * 返回自身值对象
   *
   * @param ad 原 po 列表
   * @return 自身值对象
   */
  @Named("poToVo")
  HiolabsAdVO converterToVo(HiolabsAd ad);
  /**
   * 返回自身值对象 list
   *
   * @param ad 原 po 列表
   * @return 自身值对象 list
   */
  List<HiolabsAdVO> converterToVoList(List<HiolabsAd> ad);

  /**
   * VO 转 po
   *
   * @param ad vo 值对象
   * @return po 对象
   */
  HiolabsAd converterToPo(HiolabsAdVO ad);

  /**
   * 后台传入数据转 po
   *
   * @param dto 后台数据
   * @return po 对象
   */
  @Mapping(target = "endTime", expression = "java(cn.outsourcing.supermarket.common.utils.DataUtils.toSeconds(dto.getEndTime()))")
  HiolabsAd converterBackstageAdInfoToPo(BackstageAdInfoDTO dto);

  /**
   * 转化为后台值对象
   *
   * @param ad 原 po 类
   * @return 后台值对象
   */
  @Mapping(
      target = "endTime",
      expression =
          "java(cn.outsourcing.supermarket.common.utils.DataUtils.getTimestampAllData(ad.getEndTime()))")
  @Named("poToBackstageVo")
  BackstageAdInfoVO converterToBackstageVo(HiolabsAd ad);
  /**
   * 转化为后台值对象 list
   *
   * @param ad 原 po 类
   * @return 后台值对象 list
   */
  @IterableMapping(qualifiedByName = "poToBackstageVo")
  List<BackstageAdInfoVO> converterToBackstageVoList(List<HiolabsAd> ad);
}
